<?php

/* Convert string to hex */
function s2h($str){
    $h='';
    for ($i=0; $i < strlen($str); $i++){
        $h .= dechex(ord($str[$i]));
    }
    return $h;
}

/* Convert hex to string */

function h2s($h){
    $str='';
    for ($i=0; $i < strlen($h)-1; $i+=2){
        $str .= chr(hexdec($h[$i].$h[$i+1]));
    }
    return $str;
}

// example :
$data = 'noorahmad';

$hex = s2h($data);
print $hex;
echo '<br>';
$str = h2s($hex);
echo '<br>';
print $str;

?>